package com.jason.library.common.ext

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Toast

/**
 * Activity 增加一个跳转的拓展函数
 * @receiver Activity
 * @param clazz Class<out Any>
 */
fun Activity.start(clazz: Class<out Any>) {
    startActivity(Intent(this, clazz))
}

/**
 * Activity 增加一个跳转的拓展函数,并且带参数[Bundle]
 * @receiver Activity
 * @param clazz Class<out Any>
 * @param bundle Bundle
 */
fun Activity.start(clazz: Class<out Any>, bundle: Bundle) {
    val intent = Intent(this, clazz)
    intent.putExtras(bundle)
    startActivity(intent)
}

/**
 * Activity 增加一个获取view对象的拓展函数,并且带参数[resId]
 * @receiver Activity
 * @param resId Int
 * @return T
 */
fun <T : View> Activity.getView(resId: Int) :T{
    return findViewById(resId)
}

/**
 * Activity 增加一个跳转的拓展函数,用来简化toast提示
 *
 * @receiver Activity
 * @param text String 提示文案
 */
fun Activity.showToast(text: String) {
    Toast.makeText(this.applicationContext, text, Toast.LENGTH_SHORT).show()
}

/**
 * Activity 增加一个跳转的拓展函数,用来简化toast提示
 *
 * @receiver Activity
 * @param resId Int 提示文案资源Id
 */
fun Activity.showToast(resId: Int) {
    Toast.makeText(this.applicationContext, resId, Toast.LENGTH_SHORT).show()
}



